\documentclass[a4paper]{report}
\usepackage{geometry}
\usepackage[normalem]{ulem}
\geometry{letterpaper,tmargin=1.0in,bmargin=1.0in,lmargin=1.0in,rmargin=1.0in}
\setlength\parskip{12pt}
\setlength\parindent{12pt}


%\usepackage{savetrees}
\usepackage{amssymb}
\usepackage{graphicx}
\begin{document}   

\author{ Justin Graffagnini, Greg Winn, Yujun Liu }
\title{Robot Project}
\date{Nov 28, 2011}
\maketitle

    In designing the code, the project specifications greatly influenced our decisions. Since the program had to be multithreaded,
   and the function of each thread was stated in the assignment, we programmed accordingly.

    The program has three threads: one accepts input from the keyboard, one writes commands to the robot, and one reads and prints
   sensor data. Since all of these threads are running constantly, the coexistence of the first two immediately presents a race
   condition.

    Since the writer thread (called moveThread in the code) can’t write input that doesn’t exist, we had to implement a buffer to
   store inputs, allowing moveThread to send commands to the robot only when valid input was available. The two threads shared
   this buffer, and three mutex semaphores were employed to exact control over this critical section and guard against the race
   condition. Justin wrote the keyThread, Yujun wrote the moveThread, and Greg wrote the buffer and its semaphores.

    Each of these threads has a few helper functions. The keyThread has isValidKey(), which validates input before putting it in the 
   buffer. The moveThread has several functions it can call depending on the input it reads from the buffer. The buffer itself has 
   addBufferItem() and getBufferItem(), which both implement the necessary semaphore manipulation to protect the critical section.

    The sensorThread is comparatively simple. It requests data from the robot at a frequency of 20Hz using usleep(). It then uses
   binary arithmetic to calculate the values of this data and print them out (if showData is 1). The sensor thread was primarily
   written and debugged by Greg, with Justin and Yujun figuring out how writing, reading, and requesting the appropriate packets
   worked.

    Outside of the three threads, there are some basic string definitions and initializer functions to configure the port and connect
   to the robot. Main() initializes the semaphores, runs the initialize functions, runs the threads, and then sleeps.

    Deadlocks  were not really a concern, since the mutex design is quite simple for this project.                                                                                                                             

~                                                                                                                                                                                                                              
~                                                                                                        

\end{document}

